package OOP;

import java.io.Serializable;

public class Rectangle implements Serializable {
    private double width;
    private double height;

    public Rectangle() {
        width = 1;
        height = 1;
    }

    public Rectangle(double width) {
        this.width = width;
        this.height = width;
    }

    public Rectangle(double width, double height) {
        this.width = width;
        this.height = height;
    }

    public double Perimeter() {
        return (width + height) * 2;
    }

    public double Area() {
        return width * height;
    }

    @Override
    public String toString(){
        return "长:"+this.height+" 宽:"+this.width;
    }
    public static void main(String[]args){
        Rectangle rectangle1=new Rectangle();
        Rectangle rectangle2=new Rectangle(2);
        Rectangle rectangle3=new Rectangle(3,4);
        System.out.println("rectangle1 "+rectangle1);
        System.out.println("周长："+rectangle1.Perimeter());
        System.out.println("面积："+rectangle1.Area());
        System.out.println("rectangle2 "+rectangle2);
        System.out.println("周长："+rectangle2.Perimeter());
        System.out.println("面积："+rectangle2.Area());
        System.out.println("rectangle3 "+rectangle3);
        System.out.println("周长："+rectangle3.Perimeter());
        System.out.println("面积："+rectangle3.Area());
    }

}